<?php
	header("Content-type: text/html; charset=utf-8");
	include("TopClient.php");
	include("PictureUploadRequest.php");
	$appkey = "12676595";
	$secret = "b9e6c16ad5e1fdbbdb114059bb832ef9";
	$sessionKey = $_SESSION["access_token"];
	if($sessionKey){
		$c = new TopClient;
		$c->appkey = $appkey;
		$c->secretKey = $secret;

		$req = new PictureUploadRequest;
		$req->setPictureCategoryId(0);
		//附件上传的机制参见PHP CURL文档，在文件路径前加@符号即可
		$req->setImg("@_FILES['userfile']");
		$req->setImageInputTitle("Test.jpg");
		$req->setTitle("ChouJiang TuPian BuYao ShanChu");
		$resp = $c->execute($req, $sessionKey);
		if($resp->code&&$resp->msg){
			$data["status"]=0;
			$data["message"]=$resp->msg.$resp->sub_msg;
		}else{
			$data["status"]=1;
			$data["type"]="ajax";
			$data["name"]="@_FILES['userfile']";
			$data["url"]=(string)$resp->picture->picture_path;
		}
	}else{
			$data["status"]=0;
			$data["message"]="not login";
	}
	$data = json_encode($data);
	$re = $_GET["callback"]?$_GET["callback"].'('.$data.')':$data;
	echo $re;